package views;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JToolBar;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.border.TitledBorder;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JComboBox;
import javax.swing.JMenuItem;
import javax.swing.ImageIcon;
import javax.swing.JList;

public class Chrono extends JFrame {

	private JPanel contentPane;
	private JButton btnCrerUnvnement;
	private Event Event;
	private JDesktopPane desktopPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Chrono frame = new Chrono();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Chrono() {
		initComponents();
		createEvents();

	}
	private void initComponents(){
		setTitle("Chrono");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 658, 427);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFichier = new JMenu("Fichier");
		menuBar.add(mnFichier);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.setIcon(new ImageIcon("C:\\Users\\qmpq\\Desktop\\22.png"));
		mnFichier.add(mntmExit);
		
		JMenu mnAfficher = new JMenu("Afficher");
		menuBar.add(mnAfficher);
		
		JMenu mnAbout = new JMenu("About");
		menuBar.add(mnAbout);
		
		JMenuItem mntmHelp = new JMenuItem("About this !");
		mntmHelp.setIcon(new ImageIcon("C:\\Users\\qmpq\\Desktop\\Picture.png"));
		mnAbout.add(mntmHelp);
		
		JMenu mnHelp = new JMenu("Help !");
		menuBar.add(mnHelp);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		btnCrerUnvnement = new JButton("Cr\u00E9er un \u00E9v\u00E8nement");
		
		
		contentPane.add(btnCrerUnvnement, BorderLayout.SOUTH);
		
		desktopPane = new JDesktopPane();
		desktopPane.setBackground(SystemColor.inactiveCaption);
		contentPane.add(desktopPane, BorderLayout.CENTER);
		
		JButton btnChargervnement = new JButton("Charger \u00E9v\u00E8nement");
		
		JButton btnNewButton = new JButton("Modifier \u00E9v\u00E8nement");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		
		JButton btnNewButton_1 = new JButton("Supprimer \u00E9v\u00E8nement");
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Liste des \u00E9v\u00E8nements", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout gl_desktopPane = new GroupLayout(desktopPane);
		gl_desktopPane.setHorizontalGroup(
			gl_desktopPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_desktopPane.createSequentialGroup()
					.addGroup(gl_desktopPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_desktopPane.createSequentialGroup()
							.addGap(41)
							.addComponent(btnChargervnement)
							.addGap(54)
							.addComponent(btnNewButton)
							.addGap(59)
							.addComponent(btnNewButton_1))
						.addGroup(gl_desktopPane.createSequentialGroup()
							.addGap(85)
							.addComponent(panel, GroupLayout.PREFERRED_SIZE, 420, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(85, Short.MAX_VALUE))
		);
		gl_desktopPane.setVerticalGroup(
			gl_desktopPane.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_desktopPane.createSequentialGroup()
					.addGap(47)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
					.addGroup(gl_desktopPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnChargervnement)
						.addComponent(btnNewButton)
						.addComponent(btnNewButton_1))
					.addContainerGap())
		);
		
		JList list = new JList();
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(list, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(list, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(40, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		desktopPane.setLayout(gl_desktopPane);
	}
	
	
	
	private  void createEvents(){
		
		btnCrerUnvnement.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(Event == null || Event.isClosed()){
				Event= new Event();
				desktopPane.add(Event);
				Event.show();
				}
			}
		});
	}
}
